package com.initialize.pub.dao;

import com.initialize.pub.generate.pojo.Article;
import com.initialize.pub.generate.pojo.Classification;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ClassificationDAO {
    @Select({
            "SELECT * FROM classification"
    })
    @Results({
            @Result(column = "cid", property = "cid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "ccid", property = "ccid", jdbcType = JdbcType.INTEGER),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR)
    })
    List<Classification> getAllTheCategories();

    @Select({
            "SELECT * FROM article WHERE label = #{id}"
    })
    @Results({
            @Result(column="aid", property="aid", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
            @Result(column="classification", property="classification", jdbcType=JdbcType.VARCHAR),
            @Result(column="label", property="label", jdbcType=JdbcType.VARCHAR),
            @Result(column="release_time", property="releaseTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="browse_the_number", property="browseTheNumber", jdbcType=JdbcType.INTEGER),
            @Result(column="thumb_up_number", property="thumbUpNumber", jdbcType=JdbcType.INTEGER),
            @Result(column="content", property="content", jdbcType=JdbcType.LONGVARCHAR)
    })
    List<Article> getsArticlesForEachCategory(@Param("id") int id);

    @Select({
            "SELECT COUNT(cid) FROM classification"
    })
    int selNum();
}
